import 'dart:convert';

import 'package:lai_zhan/common/model/activity/activity.dart';
import 'package:lai_zhan/common/net/HttpManager.dart';
import 'package:lai_zhan/common/dao/DataResult.dart';
import 'package:lai_zhan/common/util/LocalStorage.dart';
import 'package:lai_zhan/common/config/Config.dart';
import 'package:lai_zhan/common/redux/AppState.dart';
import 'package:redux/redux.dart';
import 'package:lai_zhan/common/net/ResultData.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:lai_zhan/common/redux/ActivityRedux.dart';

class ActivityDao {

  //获取三个acitivy
  static get3Activity(Store<AppState> store)async{

    var params = {"contain":3,"page":1,};
    print(params);
    ResultData res = await HttpManager.netPost('/activity/select/list', params);
    print(res.result);
    if(res.result){
      print(res.data);
      var source = json.decode(res.data)["msg"]["objects"];
      print(source);
      var list = getActivityList(source);
      print(list[0]);
      LocalStorage.save(Config.ACTIVITYS, res.data);
      return new DataResult(list, res.result);
    }else{
      LocalStorage.get(Config.ACTIVITYS).then((activitys){
        if(activitys==null) return new DataResult(null, false);

      });
    }
  }

  //转化activity
  static List<Activity> getActivityList(List<dynamic> list){
    List<Activity> result = [];
    list.forEach((item){
      result.add(Activity.fromJson(item));
    });
    return result;
  }

}